export default function maxSubArrayComp(nums: number[]): number {
  const n = nums.length;
  let preValue = nums[0];

  let max = nums[0];
  for (let i = 1; i < n; i++) {
    preValue = Math.max(nums[i], nums[i] + preValue);
    max = Math.max(preValue, max);
  }

  return max;
}
